<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap.css">
</head>
<body>
    <div id="countent"></div>
    <template id="tem1">
        <div class="container">
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>姓名</th>
                        <th>年龄</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="i in users">
                        <td>{{i.id}}</td>
                        <td>{{i.username}}</td>
                        <td>{{i.age}}</td>
                        <td>
                            <button @click="del(i.id)" class="btn btn-danger">删除</button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </template>
    <script src="./js/jquery.min.js"></script>
    <script src="./js/vue.min.js"></script>
    <script>
        var vm=new Vue({
            el:'#countent',
            template:'#tem1',
            data:function(){
                return{
                    users:[]
                }
            },
            created:function(){
                this.getusers()
            },
            methods:{
                // 获取数据
                getusers:function(){
                    var _this=this
                    $.get('/Users/index',function(result){
                        _this.users=result
                    })
                },
                // 删除
                del:function(id){
                    $.get('/Users/del',{id:id}).done(function(){
                        location.reload()
                    })
                }
            }
        })
    </script>
</body>
</html>